//jes论坛菜单
Jes.Fmenu ={
	init : function(){
		if(!Jes.userSess()) return;
		this.query();
		Jes.show('div_detail');
	}
	,query : function(){
		Jes.action('getFmenuTree@App',{drag:'1',sync:'1',role:'0'},function(data){
			Jes.html('fmenu_tree',data);
			treeObj = new JSDragDropTree();
			treeObj.fn = 'Jes.Fmenu.edit';
			//treeObj.setImageFolder('../../components/drag-drop-folder-tree/images/');//设置图片路径
			treeObj.setTreeId('dhtml_tree');
			treeObj.setMaximumDepth(10);
			treeObj.setAddAllowed(true);
			treeObj.setEditAllowed(true);
			treeObj.setDeleteAllowed(true);
			treeObj.setUserFunctionAfterDropDragableNodes(function(id,pId){Jes.Fmenu.moveNode(id,pId)});
			treeObj.setMessageMaximumDepthReached('超过最多级别'); // If you want to show a message when maximum depth is reached, i.e. on drop.
			treeObj.initTree();
			//treeObj.expandAll();
			treeObj.expand(true);
		});
	}
	,moveNode : function(id,pId){
		if(id && pId){
			if(confirm("确定要移动此节点吗？")){
				Jes.save('jes.movefmenu',{param:{id:id,pid:pId},isLoad:false},function(da){alert(da);});
			}else{
				JSTreeObj.cancelDropDragableNodes();
			}
		}
	}
	,edit : function(id){
		var pTitle = Jes(id).parentNode.parentNode.getElementsByTagName("A")[0].innerHTML;
		editTreeNode(id,pTitle);
	}
	,opTreeNode : function(id,pTitle){
		Jes.show('div_detail'),pTitle=pTitle||'';
		if(id=='0'){
			Jes.html('div_detail','<h3>'+pTitle+'</h3>')
		}else{
			Jes.html('div_detail',Jes.html('div_op'));
			if(id){
				Jes.html('op_title','栏目菜单编辑');
				Jes.val('pname',pTitle);
				Jes.queryO('TJesFmenu',{param:{id:id},isLoad:0},function(da){
					Jes.vals(da);;
					Jes.Upload.showImg('ta_query1_img',da.img);//,217,62
					Jes.each(['isimg','islink','isnew','istnew'],function(i,it){
						Jes.Fmenu.sel(it);
					});
				});
			}else{
				Jes.vals({op_title:'栏目菜单新增',id:'',name:'',status:1,orderidx:0,remark:'',createtime:'new',modifytime:'now',pname:pTitle});
			}
		}
		//alert(Jes.html('op_button'))
	}
	,save : function(){
		var param = Jes.vals('form1','',0);
		if(param ==null) return;
		if(param.isimg=='1'){
			if(!param['ta_query1_img.upname']){
				alert('请上传栏目图片!');
				return;
			}
		}
		param.img = param['ta_query1_img.upname'];
		Jes.save("TJesFmenu",{param:param},function(da){
			alert('保存成功!');
			if(Jes.val('id')==''){
				treeObj._addTreeNode(da.parentid,da.id,da.name);
				Jes.hide('div_detail');
			}else{
				treeObj._editTreeNode(da.id,da.name);
			}
		});
	}
	,sel : function(el){
		var val = Jes.val(el);
		if(val=='1') Jes.show(el+'_div');
		else Jes.hide(el+'_div');
	}
}


function addTreeNode(pId,pTitle){
	Jes.Fmenu.opTreeNode();
	Jes.vals({'parentid':pId,'pname':pTitle});
}


function editTreeNode(id,pTitle){
	Jes.Fmenu.opTreeNode(id,pTitle);
}

function deleteTreeNode(id,title){
	Jes.sql({ids:id,sql:"fmenu_delete_hql@bs"},function(){
		Jes.hide('div_detail');
		treeObj._deleteTreeNode(id);
	});
}